package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlQuiz entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlQuiz
 * @author MyEclipse Persistence Tools
 */

public class MdlQuizDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(MdlQuizDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String NAME = "name";
	public static final String INTRO = "intro";
	public static final String INTROFORMAT = "introformat";
	public static final String TIMEOPEN = "timeopen";
	public static final String TIMECLOSE = "timeclose";
	public static final String PREFERREDBEHAVIOUR = "preferredbehaviour";
	public static final String ATTEMPTS = "attempts";
	public static final String ATTEMPTONLAST = "attemptonlast";
	public static final String GRADEMETHOD = "grademethod";
	public static final String DECIMALPOINTS = "decimalpoints";
	public static final String QUESTIONDECIMALPOINTS = "questiondecimalpoints";
	public static final String REVIEWATTEMPT = "reviewattempt";
	public static final String REVIEWCORRECTNESS = "reviewcorrectness";
	public static final String REVIEWMARKS = "reviewmarks";
	public static final String REVIEWSPECIFICFEEDBACK = "reviewspecificfeedback";
	public static final String REVIEWGENERALFEEDBACK = "reviewgeneralfeedback";
	public static final String REVIEWRIGHTANSWER = "reviewrightanswer";
	public static final String REVIEWOVERALLFEEDBACK = "reviewoverallfeedback";
	public static final String QUESTIONSPERPAGE = "questionsperpage";
	public static final String SHUFFLEQUESTIONS = "shufflequestions";
	public static final String SHUFFLEANSWERS = "shuffleanswers";
	public static final String QUESTIONS = "questions";
	public static final String SUMGRADES = "sumgrades";
	public static final String GRADE = "grade";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String TIMELIMIT = "timelimit";
	public static final String PASSWORD = "password";
	public static final String SUBNET = "subnet";
	public static final String BROWSERSECURITY = "browsersecurity";
	public static final String DELAY1 = "delay1";
	public static final String DELAY2 = "delay2";
	public static final String SHOWUSERPICTURE = "showuserpicture";
	public static final String SHOWBLOCKS = "showblocks";

	public void save(MdlQuiz transientInstance) {
		log.debug("saving MdlQuiz instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlQuiz persistentInstance) {
		log.debug("deleting MdlQuiz instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlQuiz findById(java.lang.Long id) {
		log.debug("getting MdlQuiz instance with id: " + id);
		try {
			MdlQuiz instance = (MdlQuiz) getSession().get(
					"idv.loveloser.dao.MdlQuiz", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlQuiz instance) {
		log.debug("finding MdlQuiz instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlQuiz")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlQuiz instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlQuiz as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByIntro(Object intro) {
		return findByProperty(INTRO, intro);
	}

	public List findByIntroformat(Object introformat) {
		return findByProperty(INTROFORMAT, introformat);
	}

	public List findByTimeopen(Object timeopen) {
		return findByProperty(TIMEOPEN, timeopen);
	}

	public List findByTimeclose(Object timeclose) {
		return findByProperty(TIMECLOSE, timeclose);
	}

	public List findByPreferredbehaviour(Object preferredbehaviour) {
		return findByProperty(PREFERREDBEHAVIOUR, preferredbehaviour);
	}

	public List findByAttempts(Object attempts) {
		return findByProperty(ATTEMPTS, attempts);
	}

	public List findByAttemptonlast(Object attemptonlast) {
		return findByProperty(ATTEMPTONLAST, attemptonlast);
	}

	public List findByGrademethod(Object grademethod) {
		return findByProperty(GRADEMETHOD, grademethod);
	}

	public List findByDecimalpoints(Object decimalpoints) {
		return findByProperty(DECIMALPOINTS, decimalpoints);
	}

	public List findByQuestiondecimalpoints(Object questiondecimalpoints) {
		return findByProperty(QUESTIONDECIMALPOINTS, questiondecimalpoints);
	}

	public List findByReviewattempt(Object reviewattempt) {
		return findByProperty(REVIEWATTEMPT, reviewattempt);
	}

	public List findByReviewcorrectness(Object reviewcorrectness) {
		return findByProperty(REVIEWCORRECTNESS, reviewcorrectness);
	}

	public List findByReviewmarks(Object reviewmarks) {
		return findByProperty(REVIEWMARKS, reviewmarks);
	}

	public List findByReviewspecificfeedback(Object reviewspecificfeedback) {
		return findByProperty(REVIEWSPECIFICFEEDBACK, reviewspecificfeedback);
	}

	public List findByReviewgeneralfeedback(Object reviewgeneralfeedback) {
		return findByProperty(REVIEWGENERALFEEDBACK, reviewgeneralfeedback);
	}

	public List findByReviewrightanswer(Object reviewrightanswer) {
		return findByProperty(REVIEWRIGHTANSWER, reviewrightanswer);
	}

	public List findByReviewoverallfeedback(Object reviewoverallfeedback) {
		return findByProperty(REVIEWOVERALLFEEDBACK, reviewoverallfeedback);
	}

	public List findByQuestionsperpage(Object questionsperpage) {
		return findByProperty(QUESTIONSPERPAGE, questionsperpage);
	}

	public List findByShufflequestions(Object shufflequestions) {
		return findByProperty(SHUFFLEQUESTIONS, shufflequestions);
	}

	public List findByShuffleanswers(Object shuffleanswers) {
		return findByProperty(SHUFFLEANSWERS, shuffleanswers);
	}

	public List findByQuestions(Object questions) {
		return findByProperty(QUESTIONS, questions);
	}

	public List findBySumgrades(Object sumgrades) {
		return findByProperty(SUMGRADES, sumgrades);
	}

	public List findByGrade(Object grade) {
		return findByProperty(GRADE, grade);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByTimelimit(Object timelimit) {
		return findByProperty(TIMELIMIT, timelimit);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findBySubnet(Object subnet) {
		return findByProperty(SUBNET, subnet);
	}

	public List findByBrowsersecurity(Object browsersecurity) {
		return findByProperty(BROWSERSECURITY, browsersecurity);
	}

	public List findByDelay1(Object delay1) {
		return findByProperty(DELAY1, delay1);
	}

	public List findByDelay2(Object delay2) {
		return findByProperty(DELAY2, delay2);
	}

	public List findByShowuserpicture(Object showuserpicture) {
		return findByProperty(SHOWUSERPICTURE, showuserpicture);
	}

	public List findByShowblocks(Object showblocks) {
		return findByProperty(SHOWBLOCKS, showblocks);
	}

	public List findAll() {
		log.debug("finding all MdlQuiz instances");
		try {
			String queryString = "from MdlQuiz";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlQuiz merge(MdlQuiz detachedInstance) {
		log.debug("merging MdlQuiz instance");
		try {
			MdlQuiz result = (MdlQuiz) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlQuiz instance) {
		log.debug("attaching dirty MdlQuiz instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlQuiz instance) {
		log.debug("attaching clean MdlQuiz instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}